package com.example.administrator.boxuegu.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

public class AdBannerFragment extends Fragment {
    private int adsId;
    private ImageView imageView;
    public static AdBannerFragment newInstance(int adsId) {//调用该静态方法，返回一个新的对象
        AdBannerFragment af=new AdBannerFragment();
        af.adsId=adsId;
        return af;
    }

    //onCreateView:当new出该对象后，自动执行该方法，生成界面元素
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        imageView=new ImageView(getContext());
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);//如果里面的图片大小比imageView的尺寸要小则，拉升
        return imageView;
    }

    @Override
    public void onResume() {//当界面显示屏幕上时执行，作用：设置界面元素的内容
        super.onResume();
        imageView.setImageResource(adsId);
    }
}
